﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR410Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR410Response))]
    public class RR410ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR410Response clazz;
        
        public RR410ResponseSerializer(IRR410Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("VastuseKPV");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.VastuseKPV))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("SeisugaKPV");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.SeisugaKPV))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Andmed");
            if (clazz.Andmed!=null) {
                global::Xtee.Core.SerializationMetadata metaAndmed = this.GetMetaData(clazz.Andmed);
                Writer.WriteTypeAttribute(metaAndmed.TypeQualifiedName.Namespace, metaAndmed.TypeQualifiedName.Name);
                metaAndmed.NewSerializer(clazz.Andmed).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Andmed");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="VastuseKPV") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR410Response>VastuseKPV");
                }
                clazz.VastuseKPV = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("VastuseKPV")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR410Response>VastuseKPV", Reader.LocalName);
            }
            if (Reader.LocalName=="SeisugaKPV") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR410Response>SeisugaKPV");
                }
                clazz.SeisugaKPV = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("SeisugaKPV")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR410Response>SeisugaKPV", Reader.LocalName);
            }
            if (Reader.LocalName=="Andmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR410Response>Andmed");
                }
                global::Xtee.Core.SerializationMetadata metaAndmed = this.GetMetaData<RR410Response.IAndmedType>(Reader, ">>RR410Response>Andmed", "http://producers.rr.xtee.riik.ee/producer/rr");
                clazz.Andmed = metaAndmed.NewEntity<RR410Response.IAndmedType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Andmed");
                    metaAndmed.NewSerializer(clazz.Andmed).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR410Response>Andmed", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>RR410Response>Andmed", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR410Response.AndmedType))]
        public class AndmedTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR410Response.IAndmedType clazz;
            
            public AndmedTypeSerializer(RR410Response.IAndmedType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                for (int x = 0; ((clazz.EHAK != null) 
                            && (x < clazz.EHAK.Count)); x = (x + 1)) {
                    if (clazz.EHAK[x]!=null) {
                        Writer.WriteStartElement("EHAK");
                        global::Xtee.Core.SerializationMetadata metaEHAK = this.GetMetaData(clazz.EHAK[x]);
                        Writer.WriteTypeAttribute(metaEHAK.TypeQualifiedName.Namespace, metaEHAK.TypeQualifiedName.Name);
                        metaEHAK.NewSerializer(clazz.EHAK[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="EHAK") {
                    clazz.EHAK = new System.Collections.Generic.List<global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.ICtEHAK>();
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "EHAK")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR410Response>Andmed>EHAK");
                        }
                        global::Xtee.Core.SerializationMetadata metaEHAK = this.GetMetaData<global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.ICtEHAK>(Reader, "ctEHAK", "http://producers.rr.xtee.riik.ee/producer/rr");
                        global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.ICtEHAK item = metaEHAK.NewEntity<global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.ICtEHAK>();
                        clazz.EHAK.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("EHAK");
                            metaEHAK.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                }
            }
        }
    }
}
